package com.zhichat.web.controller;

import com.zhichat.entity.SysConfigEntity;
import com.zhichat.service.AppVersionService;
import com.zhichat.service.SysConfigService;
import com.zhichat.web.api.PageUtils;
import com.zhichat.web.api.R;
import com.zhichat.web.dto.AdminAppVersionQueryDTO;
import com.zhichat.web.dto.AppVersionInfoAddOrUpdateDTO;
import com.zhichat.web.dto.AppVersionPublishDTO;
import com.zhichat.web.dto.SysConfigUpdateDTO;
import com.zhichat.web.vo.AppVersionEntityVO;
import lombok.AllArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

/**
 * admin后台管理系统配置、发布
 *
 * @Author: 团长九哥 https://space.bilibili.com/602197686
 * @CreateDate: 2024/11/22 14:30
 */
@Slf4j
@AllArgsConstructor
@RestController
@RequestMapping("/admin/sys")
public class AdminSysController {

    private final SysConfigService sysConfigService;
    private final AppVersionService appVersionService;

    /**
     * 系统配置 查询
     */
    @GetMapping("/config_info")
    public R<SysConfigEntity> sysConfigOfAdmin() {
        return R.success(sysConfigService.getSysConfigInfo());
    }

    /**
     * 系统配置 保存/修改
     */
    @PostMapping("/config_update")
    public R<SysConfigEntity> updateConfigOfAdmin(@Validated SysConfigUpdateDTO sysConfigUpdateDTO) {
        return R.success(sysConfigService.updateConfigOfAdmin(sysConfigUpdateDTO));
    }

    /**
     * 获取 APP版本列表
     */
    @GetMapping("/list_app")
    public R<PageUtils<AppVersionEntityVO>> appList(@Validated AdminAppVersionQueryDTO adminAppVersionQueryDTO) {
        return R.success(appVersionService.appList(adminAppVersionQueryDTO));
    }

    /**
     * APP版本信息 保存/修改
     */
    @PostMapping("/save_app")
    public R<String> saveAppVersionInfo(@Validated AppVersionInfoAddOrUpdateDTO appVersionInfoAddOrUpdateDTO) {
        return R.status(appVersionService.saveAppVersionInfo(appVersionInfoAddOrUpdateDTO));
    }

    /**
     * APP版本 发布
     */
    @PostMapping("/publish_app")
    public R<String> publishApp(@Validated @RequestBody AppVersionPublishDTO appVersionPublishDTO) {
        return R.status(appVersionService.publishApp(appVersionPublishDTO));
    }
}
